package com.yongqi.duocai.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yongqi.duocai.entity.Order;
import com.yongqi.duocai.entity.result.OrderInfoResult;
import com.yongqi.duocai.entity.result.OrderResult;
import com.yongqi.duocai.mapper.OrderMapper;
import com.yongqi.duocai.service.OrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 夏亮辉
 * @since 2021-06-24
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {

    @Autowired
    private OrderMapper orderMapper;

    /**
     * 根据 用户 id 查询响应订单信息
     * @param userId
     * @return
     */
    @Override
    public List<OrderResult> queryByUserId(Integer userId, String name, String no) {
        return orderMapper.selectByUserId(userId,name,no);
    }

    /**
     * 根据用户id 分页查询订单信息
     *
     * @param page
     * @param userId
     * @return
     */
    @Override
    public IPage<OrderResult> queryPageUserId(IPage<OrderResult> page, Integer userId, Integer state) {
        return orderMapper.selectByUserIdByPage(page,userId, state);
    }

    @Override
    public List<Order> queryOfUserId(Integer userId, String no) {
        QueryWrapper<Order> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id",userId)
                    .eq("no", no);
        return orderMapper.selectList(queryWrapper);
    }

    /**
     * 根据订单号查询商品详情
     *
     * @param userId
     * @param no
     * @return
     */
    @Override
    public List<OrderInfoResult> queryByNo(Integer userId, String no) {
        return orderMapper.queryByNo(userId,no);
    }

    /**
     * 根据条件查询订单
     *
     * @param userId
     * @param no
     * @return
     */
    @Override
    public List<Order> queryByCondition(Integer userId, String no) {
        QueryWrapper<Order> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("no", no)
                    .eq("user_id", userId);

        return orderMapper.selectList(queryWrapper);
    }

}
